package cn.com.cis.plugins.quartz;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import cn.com.cis.domain.JobConfig;
import cn.com.cis.domain.User;
import cn.com.cis.service.UserService;
import cn.com.cis.utils.jobExecute.JobExecuteHelper;
import lombok.Setter;

public class QrtzJobFactory implements Job {

	@Setter
	private static UserService userService;

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {

		JobDataMap dm = context.getMergedJobDataMap();
		JobConfig jobConfig = (JobConfig) dm.get(JobConfig.SCHEDULE_JOB_NAME_KEY);

		User user = userService.selectUserById(jobConfig.getSetupUserId());
		String username = "";
		if (null != user) {
			username = user.getUsername();
		}

		try {
			JobExecuteHelper.executeJobImmediate(jobConfig.getEtlXmlId(), jobConfig.getJobNameDisplay(), username);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
